package com.supreme.studyserver.service;

import com.supreme.studyserver.entity.BasicEntity;
import com.supreme.studyserver.entity.KVItem;
import org.springframework.stereotype.Service;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

@Service
public class KVIService {

    public void firstTest() {
        KVItem<String, String> kvItem = new KVItem<>();
        kvItem.setKey("hello");
        kvItem.setValue("hello world");
        System.out.println(kvItem);
    }

    public void testBaseEntityClass() {
//        final RawDao<String> stringRawDao = new RawDao<>();
//        System.out.println(stringRawDao.getClazz());

//        System.out.println(new BaseEntity<String>().getEntityClass());

        final BasicEntity<String> basicEntity = new BasicEntity<>();
//        final Class<?> entityClass = baseEntity.getEntityClass();
        final Class<?> entityClass = basicEntity.getClass();
        System.out.println(entityClass);

        final Method setNameMethod = ReflectionUtils.findMethod(entityClass, "setName", String.class);
        ReflectionUtils.invokeMethod(setNameMethod, basicEntity, "lucky ting");
//        System.out.println(baseEntity.getName());
    }
}
